//
//  CYYNetWorkManager+ObserveAParty.m
//  LetsPartyBmob
//
//  Created by rimi on 15/9/9.
//  Copyright (c) 2015年 柴阳阳. All rights reserved.
//

#import "CYYNetWorkManager+ObserveAParty.h"

@implementation CYYNetWorkManager (ObserveAParty)

//关注一个活动(删除参加 + 关注活动)
//此操作在活动详情界面操作
/*
 partyObjectId : 上一个界面推送 过程中 传值过来的。。
 */
+ (void)observeAPartyWithObjectId:(NSString *)partyObjectId
                           sucess:(Sucess)sucess
                             fail:(Fail)fail{
    [CYYNetWorkManager deleteTarkPartInPartyithObjectId:partyObjectId sucess:^(NSString *sucessString) {
        //取到改活动
        BmobObject *bmobObject = [BmobObject objectWithoutDatatWithClassName:@"Parties" objectId:partyObjectId];
        
        //新建relation对象
        BmobRelation *relation = [[BmobRelation alloc] init];
        [relation addObject:[BmobObject objectWithoutDatatWithClassName:@"_User" objectId:[CYYNetWorkManager currentUserGet].objectId]];
        
        [bmobObject addRelation:relation forKey:@"partyObservers"];
        
        //把活动关注着放到活动所有人当中
        [bmobObject addRelation:relation forKey:@"partyAllPeople"];
        
        [bmobObject updateInBackgroundWithResultBlock:^(BOOL isSuccessful, NSError *error) {
            if (isSuccessful) {
                sucess(@"关注成功");
            }else{
                fail(error);
            }
        }];
    } fail:^(NSError *error) {
        fail(error);
    }];
}

@end
